﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.BLL;
using CMS.BLL.Entity;

public partial class Controls_Tour_ctrTourBooking : System.Web.UI.UserControl
{
    private int nCurrentLanguage = Support.GetCurrentLanguage();
    //protected string sTodate = "";
    //protected string sFromdate = "";
    protected void Page_Load(object sender, EventArgs e)
    {
     
    
        if (!IsPostBack)
        {
            SetLabelLanguage();
            ValidateControl();
            BindDataToDDLAdult();
            BindDataToDDLChild();
            BindDataToDDLExtraBed();
            BindDataToDDLFullNameTitle();
            BindDataToDDLPayment();
            BindDataToDDLRoomType();
            BindDataToDay1();
            BindDataToDay2();
            BindDataToMonth1();
            BindDataToMonth2();
            BindDataToYear1();
            BindDataToYear2();
        }
    }
    private void SetLabelLanguage()
    {
        int nDefaultLanguage = Support.GetCurrentLanguage();
        lblAddress.Text = MultipleLanguage.LBL_ADDRESS[nCurrentLanguage - 1];
        lblAdult.Text = MultipleLanguage.LBLADULT[nCurrentLanguage - 1];//
        lblChild.Text = MultipleLanguage.LBLCHILD[nCurrentLanguage - 1];
        lblContactEmail.Text = MultipleLanguage.EMAIL[nCurrentLanguage - 1];
        lblContactFullname.Text = MultipleLanguage.FULLNAME[nCurrentLanguage - 1];
        lblContactPhone.Text = MultipleLanguage.TELEPHONE[nCurrentLanguage - 1];
        lblFax.Text = MultipleLanguage.LBL_FAX[nCurrentLanguage - 1];
        lblDuration.Text = MultipleLanguage.LBL_DURATION[nCurrentLanguage - 1];
        lblExtraBed.Text = MultipleLanguage.LBL_EXTRABED[nCurrentLanguage - 1];
        lblFinishDate.Text = MultipleLanguage.LBL_FINISHDATE[nCurrentLanguage - 1];
        lblFullNameTitle.Text = MultipleLanguage.LBL_FULLNAMETILE[nCurrentLanguage - 1];
        lblNationality.Text = MultipleLanguage.LBL_NATIONLITY[nCurrentLanguage - 1];
        lblOtherRequest.Text = MultipleLanguage.LBL_YOURMESSAGE[nCurrentLanguage - 1];
        lblPayment.Text = MultipleLanguage.LBL_PAYMENT[nCurrentLanguage - 1];
        lblRoomType.Text = MultipleLanguage.LBL_ROOMTYPE[nCurrentLanguage - 1];
        lblStarRating.Text = MultipleLanguage.STARRATING[nCurrentLanguage-1];
        lblStartDate.Text = MultipleLanguage.LBL_STARTDATEBOOKING[nCurrentLanguage - 1];
        lblHow.Text = MultipleLanguage.LBL_HOWABOUT[nCurrentLanguage - 1];
        //sTodate = ConvertData.ConvertIntToDatetimeString(ConvertData.ConvertDatetimeToInt(DateTime.Today));
        //sFromdate = ConvertData.ConvertIntToDatetimeString(ConvertData.ConvertDatetimeToInt(DateTime.Today));
        lblBooking.Text = MultipleLanguage.TOURBOOKING[nCurrentLanguage - 1];
        lblFlight.Text = MultipleLanguage.LBL_NAMEOFAIRLINE[nCurrentLanguage - 1];
        lblTimeRef.Text = MultipleLanguage.LBL_FLIGHTIMEREF[nCurrentLanguage - 1];

        StaticPages objStatic = new StaticPages();
        objStatic.LoadById(41);
        switch (nCurrentLanguage)
        { 
            case 1:
                ltrContentBooking.Text = ConvertData.ConvertToString(objStatic.Data.PageContent1);
                break;
            case 2:
                ltrContentBooking.Text = ConvertData.ConvertToString(objStatic.Data.PageContent2);
                break;
            case 3:
                ltrContentBooking.Text = ConvertData.ConvertToString(objStatic.Data.PageContent3);
                break;
        }

        StaticPages objStaticFooterTB = new StaticPages();
        objStaticFooterTB.LoadById(48);
        switch (nCurrentLanguage)
        { 
            case 1:
                ltrDifficultiesWhileSending.Text = ConvertData.ConvertToString(objStaticFooterTB.Data.PageContent1);
                break;
            case 2:
                ltrDifficultiesWhileSending.Text = ConvertData.ConvertToString(objStaticFooterTB.Data.PageContent2);
                break;
            case 3:
                ltrDifficultiesWhileSending.Text = ConvertData.ConvertToString(objStaticFooterTB.Data.PageContent3);
                break;
        }
    }
   
    private void ValidateControl()
    {
        rfvContactEmail.ErrorMessage = MultipleLanguage.CONTACT_EMAIL_EMPTY[nCurrentLanguage - 1];
        rfvContactFullname.ErrorMessage = MessagesValidate.Setting_FULLNAME_EMPTY[nCurrentLanguage - 1];
        rfvContactPhone.ErrorMessage = MessagesValidate.BASKET_TEL_EMPTY[nCurrentLanguage - 1];
        revEmail.ErrorMessage = MessagesValidate.Setting_EMAIL_WRONG[nCurrentLanguage - 1];

        rfvDuration.ErrorMessage = MultipleLanguage.DURATION_EMPTY[nCurrentLanguage - 1];
        rfvTour.ErrorMessage = MultipleLanguage.TOUR_EMPTY[nCurrentLanguage - 1];
    }
    #region Relative Functions    
    

    private eTourBooking setData()
    {
        TourBooking objTourBooking = new TourBooking();
        objTourBooking.Data.TourID =ConvertData.ConvertToString(txtTourName.Text.Trim());
        objTourBooking.Data.Kid = 0;
        objTourBooking.Data.Status = 0;
        objTourBooking.Data.ContactPhone = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtContactPhone.Text.Trim()));
        objTourBooking.Data.ContactFullname = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtContactFullname.Text.Trim()));
        objTourBooking.Data.ContactEmail = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtContactEmail.Text.Trim()));
        objTourBooking.Data.ContactAddress = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtContactAddress.Text.Trim()));
        objTourBooking.Data.Child = ConvertData.ConvertToInt(ddlChild.SelectedValue);
        objTourBooking.Data.BookingDate = ConvertData.ConvertDatetimeToInt(DateTime.Today);
        objTourBooking.Data.Adult = ConvertData.ConvertToInt(ddlAdult.SelectedValue);
        objTourBooking.Data.ExtraBed = ConvertData.ConvertToInt(ddlExtraBed.SelectedValue);

        objTourBooking.Data.StartedDate = ConvertData.ConvertDateStringToInt(ddlDay1.Text + "/" + ddlMonth1.SelectedValue + "/" + ddlYear1.SelectedValue);
        objTourBooking.Data.FinishedDate = ConvertData.ConvertDateStringToInt(ddlDay2.Text + "/" + ddlMonth2.SelectedValue + "/" + ddlYear2.SelectedValue);

        objTourBooking.Data.FullNameTitle = ddlFullNameTitle.SelectedValue;
        objTourBooking.Data.HotelStarRating = ConvertData.ConvertToInt(ddlStarRating.SelectedValue);
        objTourBooking.Data.Nationality = txtNationality.Text.Trim();
        objTourBooking.Data.OtherRequest = txtOtherRequest.Text.Trim();
        objTourBooking.Data.PaymentID = ConvertData.ConvertToInt(ddlPayment.SelectedValue);
        objTourBooking.Data.RoomTypeID = ConvertData.ConvertToInt(ddlRoomType.SelectedValue);
        objTourBooking.Data.Duration = ConvertData.ConvertToString(txtDuration.Text );

        objTourBooking.Data.FlightTimeRef = ConvertData.ConvertToString(txtFlight.Text);
        objTourBooking.Data.AirlineName = ConvertData.ConvertToString(txtTimeRef.Text);
        int n1 = ddlHow.SelectedIndex;
        objTourBooking.Data.HowFindUs = ConvertData.ConvertToString(ddlHow.Items[n1].Text);

        return objTourBooking.Data;
    }
    private void BindDataToDDLAdult()
    {
        for(int i=0; i<20; i++)
        {
            ListItem item = new ListItem((i + 1).ToString(), (i + 1).ToString(), true);
            ddlAdult.Items.Add(item);
        }
    }
    private void BindDataToDDLChild()
    {
        for (int i = 0; i < 21; i++)
        {
            ListItem item = new ListItem(i.ToString(), i.ToString(), true);
            ddlChild.Items.Add(item);
        }
    }
    //private void BindDataToDDLStarRating()
    //{
    //    for (int i = 0; i < 5; i++)
    //    {
    //        ListItem item = new ListItem((i + 1).ToString(), (i + 1).ToString(), true);
    //        ddlStarRating.Items.Add(item);
    //    }
    //}
    private void BindDataToDay1()
    {
        for (int i = 0; i < 31; i++)
        {
            ListItem item;
            if ((i + 1) < 10)
                item = new ListItem( (i + 1).ToString(), "0" + (i + 1).ToString(), true);
            else
                item = new ListItem((i + 1).ToString(), (i + 1).ToString(), true);
            ddlDay1.Items.Add(item);
        }
    }
    private void BindDataToDay2()
    {
        for (int i = 0; i < 31; i++)
        {
            ListItem item;
            if ((i + 1) < 10)
                item = new ListItem( (i + 1).ToString(), "0" + (i + 1).ToString(), true);
            else
                item = new ListItem((i + 1).ToString(), (i + 1).ToString(), true);
            ddlDay2.Items.Add(item);
        }
    }
    private void BindDataToMonth1()
    {
        ListItem item1;
        item1 = new ListItem(MultipleLanguage.MONTH1[nCurrentLanguage - 1], "01", true);
        ddlMonth1.Items.Add(item1);

        ListItem item2;
        item2 = new ListItem(MultipleLanguage.MONTH2[nCurrentLanguage - 1], "02", true);
        ddlMonth1.Items.Add(item2);

        ListItem item3;
        item3 = new ListItem(MultipleLanguage.MONTH3[nCurrentLanguage - 1], "03", true);
        ddlMonth1.Items.Add(item3);

        ListItem item4;
        item4 = new ListItem(MultipleLanguage.MONTH4[nCurrentLanguage - 1], "04", true);
        ddlMonth1.Items.Add(item4);

        ListItem item5;
        item5 = new ListItem(MultipleLanguage.MONTH5[nCurrentLanguage - 1], "05", true);
        ddlMonth1.Items.Add(item5);

        ListItem item6;
        item6 = new ListItem(MultipleLanguage.MONTH6[nCurrentLanguage - 1], "06", true);
        ddlMonth1.Items.Add(item6);

        ListItem item7;
        item7 = new ListItem(MultipleLanguage.MONTH7[nCurrentLanguage - 1], "07", true);
        ddlMonth1.Items.Add(item7);

        ListItem item8;
        item8 = new ListItem(MultipleLanguage.MONTH8[nCurrentLanguage - 1], "08", true);
        ddlMonth1.Items.Add(item8);

        ListItem item9;
        item9 = new ListItem(MultipleLanguage.MONTH9[nCurrentLanguage - 1], "09", true);
        ddlMonth1.Items.Add(item9);

        ListItem item10;
        item10 = new ListItem(MultipleLanguage.MONTH10[nCurrentLanguage - 1], "10", true);
        ddlMonth1.Items.Add(item10);

        ListItem item11;
        item11 = new ListItem(MultipleLanguage.MONTH11[nCurrentLanguage - 1], "11", true);
        ddlMonth1.Items.Add(item11);

        ListItem item12;
        item12 = new ListItem(MultipleLanguage.MONTH12[nCurrentLanguage - 1], "12", true);
        ddlMonth1.Items.Add(item12);
    }
    private void BindDataToMonth2()
    {
        ListItem item1;
        item1 = new ListItem(MultipleLanguage.MONTH1[nCurrentLanguage - 1], "01", true);
        ddlMonth2.Items.Add(item1);

        ListItem item2;
        item2 = new ListItem(MultipleLanguage.MONTH2[nCurrentLanguage - 1], "02", true);
        ddlMonth2.Items.Add(item2);

        ListItem item3;
        item3 = new ListItem(MultipleLanguage.MONTH3[nCurrentLanguage - 1], "03", true);
        ddlMonth2.Items.Add(item3);

        ListItem item4;
        item4 = new ListItem(MultipleLanguage.MONTH4[nCurrentLanguage - 1], "04", true);
        ddlMonth2.Items.Add(item4);

        ListItem item5;
        item5 = new ListItem(MultipleLanguage.MONTH5[nCurrentLanguage - 1], "05", true);
        ddlMonth2.Items.Add(item5);

        ListItem item6;
        item6 = new ListItem(MultipleLanguage.MONTH6[nCurrentLanguage - 1], "06", true);
        ddlMonth2.Items.Add(item6);

        ListItem item7;
        item7 = new ListItem(MultipleLanguage.MONTH7[nCurrentLanguage - 1], "07", true);
        ddlMonth2.Items.Add(item7);

        ListItem item8;
        item8 = new ListItem(MultipleLanguage.MONTH8[nCurrentLanguage - 1], "08", true);
        ddlMonth2.Items.Add(item8);

        ListItem item9;
        item9 = new ListItem(MultipleLanguage.MONTH9[nCurrentLanguage - 1], "09", true);
        ddlMonth2.Items.Add(item9);

        ListItem item10;
        item10 = new ListItem(MultipleLanguage.MONTH10[nCurrentLanguage - 1], "10", true);
        ddlMonth2.Items.Add(item10);

        ListItem item11;
        item11 = new ListItem(MultipleLanguage.MONTH11[nCurrentLanguage - 1], "11", true);
        ddlMonth2.Items.Add(item11);

        ListItem item12;
        item12 = new ListItem(MultipleLanguage.MONTH12[nCurrentLanguage - 1], "12", true);
        ddlMonth2.Items.Add(item12);

        
    }
    private void BindDataToYear1()
    {
        for (int i = 2011; i < 2015; i++)
        {
            ListItem item = new ListItem((i + 1).ToString(), (i + 1).ToString(), true);
            ddlYear1.Items.Add(item);
        }
    }
    private void BindDataToYear2()
    {
        for (int i = 2011; i < 2015; i++)
        {
            ListItem item = new ListItem((i + 1).ToString(), (i + 1).ToString(), true);
            ddlYear2.Items.Add(item);
        }
    }
    private void BindDataToDDLRoomType()
    {
        RoomType obj = new RoomType();
        DataTable dtb = new DataTable();

        dtb = obj.GetAll();
        ddlRoomType.DataSource = dtb;
        int nCurrentLang = Support.GetCurrentLanguage();
        switch (nCurrentLang)
        {
            case 1:
                ddlRoomType.DataTextField = "Description1";
                break;
            case 2:
                ddlRoomType.DataTextField = "Description2";
                break;
            case 3:
                ddlRoomType.DataTextField = "Description3";
                break;
        }
        ddlRoomType.DataValueField = "RoomType";
        ddlRoomType.DataBind();
    }
    private void BindDataToDDLExtraBed()
    {
        ListItem item = new ListItem("No", "0", true);
        ddlExtraBed.Items.Add(item);
        ListItem item1 = new ListItem("Yes", "1", true);
        ddlExtraBed.Items.Add(item1);
    }
    private void BindDataToDDLFullNameTitle()
    {
        ListItem item = new ListItem("Mr.", "Mr.", true);
        ddlFullNameTitle.Items.Add(item);
        ListItem item1 = new ListItem("Miss.", "Miss.", true);
        ddlFullNameTitle.Items.Add(item1);
        ListItem item2 = new ListItem("Mrs.", "Mrs.", true);
        ddlFullNameTitle.Items.Add(item2);
        ListItem item3 = new ListItem("Ms.", "Ms.", true);
        ddlFullNameTitle.Items.Add(item3);
        ListItem item4 = new ListItem("Dr.", "Dr.", true);
        ddlFullNameTitle.Items.Add(item4);
    }
    private void BindDataToDDLPayment()
    {
        Payment obj = new Payment();
        DataTable dtb = new DataTable();

        dtb = obj.GetAll();
        ddlPayment.DataSource = dtb;
        int nCurrentLang = Support.GetCurrentLanguage();
        ddlPayment.DataTextField = "Description";
        ddlPayment.DataValueField = "PaymentID";
        ddlPayment.DataBind();
    }
    #endregion

    #region Click Events
    protected void btnSave_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            TourBooking objTourBooking = new TourBooking();
            objTourBooking.Data = this.setData();
            int nResult = objTourBooking.Insert();
            if (nResult > 0)
            {
                Alert1.ShowMessage(1, MessagesAlert.BOOKTOUR_SUCCESSFUL[nCurrentLanguage - 1]);
                reSetLable();
            }
            else
            {
                Alert1.ShowMessage(1, MessagesAlert.UPDATE_UNSUCCESSFUL[nCurrentLanguage - 1]);
            }
        }
        catch
        {
            Response.Redirect("~/Default.aspx");
        }
    }
    #endregion

    private void reSetLable()
    {
        txtContactAddress.Text = "";
        txtContactEmail.Text = "";
        txtContactFullname.Text = "";
        txtContactPhone.Text = "";
        txtDuration.Text = "";
        txtNationality.Text = "";
        txtOtherRequest.Text = "";
        txtTourName.Text = "";
    }
    protected void btnReset_Click(object sender, ImageClickEventArgs e)
    {
        this.reSetLable();
    }
}